package org.focusj.scala.fn

/**
 * 抽象控制
 */
object Struct {
    def run(struct: => Unit) = {
        new Thread {
            override def run() {
                struct
            }
        }.start
    }
    //run(println(1))

    def run2(struct: () => Unit) = {
        new Thread {
            override def run() {
                struct()
            }
        }.start
    }
    //run2(() => println(1))

    def loop(condition: => Boolean)(struct: => Unit): Unit /*递归调用是指明给出返回值，scala没有提供递归调用函数的返回类型推断*/ = {
        if (!condition) {
            struct
            loop(condition)(struct)
        }
    }

    def main(args: Array[String]) {
        var i = 10
        loop(i == 0) { i -= 1; println(i) }

    }
}